﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Sms_Select_Mobile.aspx.cs" Inherits="JKF.Web.SMS.Sms_Select_Mobile" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .move2button { text-align: center; width: 80px; display: inline-block; float: left; }
        .move2button input { display: block; margin: 16px auto; }
    </style>
    <%= RegScript("~/js/jquery.1.5.js")%>
    <%=RegScript("~/js/Common.js")%>
    <%=RegScript("~/js/jquery.json.js")%>
    <%=RegScript("~/js/jquery.nhis.js")%>
    <%=RegScript("~/js/jquery.rchis.js")%>
    <%=RegScript("~/js/jquery.blockUI.js")%>
    <%=RegScript("~/js/jquery.validate.js")%>
    <%=RegScript("~/js/DatePicker/WdatePicker.js")%>
    <%=RegStyle("~/js/suggest/jquery.suggest.css")%>
    <%=this.RegStyle("~/App_Themes/Theme2/Include.css")%>
    <script type="text/javascript">
        var appPath = "<%=AppPath %>";
        var tmpl = new DTemplate();
        var areaHandler = appPath + '/do/Dic/Dic_Area.do';
        var handler = appPath + "/do/SMS/SmsModule.do";
        var customerHandler = appPath + "/do/Customer/Customer.do";
        var optMobile = "[${CARD_NO}][${NAME}][${MOBILE}]";
        var dtReg = /^\d{4}(\/|-)([1][0-2]|[1-9]|0[1-9])(\/|-)([1-2][0-9]|3[0-1]|[1-9]|0[1-9])( (0?[0-9]|1[0-9]|2[0-4])(:([0-5][0-9])){1,2})?$/;

        $(function () {
            BindEvent();
        });

        function BindEvent() {
            $("#ownShop").Suggest({
                url: appPath + "/do/Shop/Shop.do", data: { ActionName: "SuggestGetAllShop" }, onSelect: function (data, selectedIndex, selectedItem) {
                    var dr = data.Data.Tables[0].Rows[selectedIndex];
                    $("#ownShop").val(dr.SHOP_NAME);
                    $("#SHOP_CODE").val(dr.SHOP_CODE);
                }, mutiPage: true, minChars: 0, cache: true
            });
            $("#province").change(function () {
                $("#city").val("");
                $("#AREA_CODE").val("");
                $("#city").attr("disabled", "disabled");
                $("#AREA_CODE").attr("disabled", "disabled");
                if ($(this).val().length > 0) {
                    $.post(areaHandler, { ActionName: "GetAreaJson", code: $(this).val() }, function (obj) {
                        if (obj.Success) {
                            $("#city").empty();
                            $("#city").html("<option value=''>请选择</option>" + tmpl("<option value=\"${value}\">${text}</option>", obj.Data, true)).removeAttr("disabled");
                            if ($("#city").attr("pvl")) {
                                $("#city").val($("#city").attr("pvl")).change();
                            }
                        }
                    }, "json");
                }
            });
            $("#city").change(function () {
                $("#AREA_CODE").val("");
                $("#AREA_CODE").attr("disabled", "disabled");
                if ($(this).val().length > 0) {
                    $.post(areaHandler, { ActionName: "GetAreaJson", code: $(this).val() }, function (obj) {
                        if (obj.Success) {
                            $("#AREA_CODE").empty();
                            $("#AREA_CODE").html("<option value=''>请选择</option>" + tmpl("<option value=\"${value}\">${text}</option>", obj.Data, true)).removeAttr("disabled");
                            if ($("#AREA_CODE").attr("pvl")) $("#AREA_CODE").val($("#AREA_CODE").attr("pvl"));
                        }
                    }, "json");
                }
            });

            alxVr.push({
                id: "MEMODAY_FROM",
                rule: function (cn) {
                    var curVl = $.trim(cn.val());
                    if (curVl.length == 0) return true;
                    if (!dtReg.test(curVl)) {
                        this.msg = "起始日期格式不正确.";
                        return false;
                    }
                    return true;
                }
            });

            alxVr.push({
                id: "MEMODAY_To",
                rule: function (cn) {
                    var curVl = $.trim(cn.val());
                    if (curVl.length == 0) return true;
                    if (!dtReg.test(curVl)) {
                        this.msg = "截止日期格式不正确.";
                        return false;
                    }
                    return true;
                }
            });

            alxVr.push({
                id: "AGEF_FROM",
                rule: function (cn) {
                    var curVl = $.trim(cn.val());
                    if (curVl.length == 0) return true;
                    if (!/^\d+$/.test(curVl)) {
                        this.msg = "年龄起始值格式不正确.";
                        return false;
                    }
                    return true;
                }
            });
            alxVr.push({
                id: "AGE_TO",
                rule: function (cn) {
                    var curVl = $.trim(cn.val());
                    if (curVl.length == 0) return true;
                    if (!/^\d+$/.test(curVl)) {
                        this.msg = "年龄结束值格式不正确.";
                        return false;
                    }
                    return true;
                }
            });
            alxVr.push({
                id: "CONSUME_POINT_FROM",
                rule: function (cn) {
                    var curVl = $.trim(cn.val());
                    if (curVl.length == 0) return true;
                    if (!/^\d+$/.test(curVl)) {
                        this.msg = "消费积分起始值格式不正确.";
                        return false;
                    }
                    return true;
                }
            });
            alxVr.push({
                id: "CONSUME_POINT_TO",
                rule: function (cn) {
                    var curVl = $.trim(cn.val());
                    if (curVl.length == 0) return true;
                    if (!/^\d+$/.test(curVl)) {
                        this.msg = "消费起始结束格式不正确.";
                        return false;
                    }
                    return true;
                }
            });
            alxVr.push({
                id: "CUSTOMER_MOBILE",
                rule: function (cn) {
                    var curVl = $.trim(cn.val());
                    if (curVl.length == 0) return true;
                    if (!/^\d+$/.test(curVl)) {
                        this.msg = "手机号码只允许输入数字.";
                        return false;
                    }
                    return true;
                }
            });
            $.validateBind();

            $("#CUSTOMER_SOURCE").dblclick(function () { moveTo($("#CUSTOMER_SOURCE"), $("#CUSTOMER_TARGET")); });
            $("#CUSTOMER_TARGET").dblclick(function () { moveTo($("#CUSTOMER_TARGET"), $("#CUSTOMER_SOURCE")); });
            $("#btnMove").click(function () { moveTo($("#CUSTOMER_SOURCE"), $("#CUSTOMER_TARGET")); });
            $("#btnMoveAll").click(function () { moveAllTo($("#CUSTOMER_SOURCE"), $("#CUSTOMER_TARGET")); });
            $("#btnBack").click(function () { moveTo($("#CUSTOMER_TARGET"), $("#CUSTOMER_SOURCE")); });
            $("#btnBackAll").click(function () { moveAllTo($("#CUSTOMER_TARGET"), $("#CUSTOMER_SOURCE")); });
            $("#btnSearch").click(Searchmobile);
            $("#btnConfirm").click(function () {
                var mobiles = {};
                $("#CUSTOMER_TARGET").find("option").each(function () {
                    var vl = $.trim($(this).val());
                    if (vl.length > 0) mobiles[vl] = true;
                });
                var selMobile = [];
                for (var s in mobiles) selMobile.push(s);
                top.popRetuInfo(selMobile);
                top.tipsWindown.close();
            });
        }
        function Searchmobile() {
            if (!$.validateAll()) {
                if ($(".alxv-failed").size() > 0) {
                    $(document).scrollTop($(".alxv-failed").eq(0).scrollTop());
                }
                return;
            };
            var srchOption = {
                CARD_NO: $.trim($("#CUSTOMER_CARD_NO").val()),
                CARD_NAME: $.trim($("#CUSTOMER_CARD_NAME").val()),
                MEMODAYTYPE: $.trim($("#MEMODAYTYPE").val()),
                MEMODAY_FROM: $.trim($("#MEMODAY_FROM").val()),
                MEMODAY_TO: $.trim($("#MEMODAY_To").val()),
                CUSTOMER_LEVEL: $.trim($("#CUSTOMER_LEVEL").val()),
                CUSTOMER_GENDER: $.trim($("#CUSTOMER_GENDER").val()),
                AGE_FROM: $.trim($("#AGE_FROM").val()),
                AGE_TO: $.trim($("#AGE_TO").val()),
                POINT_FROM: $.trim($("#CONSUME_POINT_FROM").val()),
                POINT_TO: $.trim($("#CONSUME_POINT_TO").val()),
                AREA_CODE: getAreaCode(),
                RemoveNoMobile: $("#RemoveNoMobile").attr("checked"),
                SHOP_CODES: $.trim($("#ownShop").val()),
                MOBILE_NUM: $.trim($("#CUSTOMER_MOBILE").val()),
                SHOP_CODE: $.trim($("#SHOP_CODE").val())
            };

            $.post(customerHandler, { ActionName: "SearchCustomerMobile", srchJson: $.toJSON(srchOption) }, function (rslt) {
                $("#CUSTOMER_SOURCE").empty();
                if (rslt.Success) {
                    var optvl;
                    $(rslt.Data).each(function () {
                        optvl = tmpl(optMobile, this, true);
                        $("#CUSTOMER_SOURCE").append($("<option></option>").text(optvl).attr("value", this.MOBILE));
                    });
                    updateSelectCount();
                    return;
                }
                alert(rslt.Message);
            }, "json");
        }

        function moveAllTo(src, tgt) {
            var options = src.find("option");
            $(options).each(function () { tgt.append($(this)); });
            updateSelectCount();
        }

        function updateSelectCount() {
            $("#sourceNum").text($("#CUSTOMER_SOURCE").find("option").size() + "名");
            $("#targetNum").text($("#CUSTOMER_TARGET").find("option").size() + "名");
        }

        function moveTo(src, tgt) {
            var sel = src.val();
            $(sel).each(function () { tgt.append(src.find("option[value='" + this + "']")); });
            updateSelectCount();
        }

        function getAreaCode() {
            var ca = $.trim($.FxNull($("#AREA_CODE").val(), ""));
            var cc = $.trim($.FxNull($("#city").val(), ""));
            var cp = $.trim($.FxNull($("#province").val(), ""));
            if (ca != "") return ca;
            if (cc != "") return cc;
            if (cp != "") return cp;
            return "";
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div class="pop__body" style="margin: 10px 42px 29px 42px;">
            <p class="mb8 f14"><strong>第一步：设定搜索条件</strong></p>
            <div class="common_search">
                <div class="l_h45">
                    <span class="mr30 mb20">顾客卡号：
                    <input id="CUSTOMER_CARD_NO" type="text" class="common_search_input w100" />
                    </span>
                    <span class="mr30 mb20">手机：<input id="CUSTOMER_MOBILE" type="text" class="common_search_input w100" />
                    </span>
                    <span class="mr30 mb20">姓名：<input id="CUSTOMER_CARD_NAME" type="text" class="common_search_input w100" />
                    </span>
                    <span class="mr30 mb20">性别：
                        <select id="CUSTOMER_GENDER" class="common_search_select w100">
                            <option value="">请选择</option>
                            <option value="0">男</option>
                            <option value="1">女</option>
                        </select>
                    </span>
                    <br />
                    <span class="mr30 mb20">顾客级别：
                    <select id="CUSTOMER_LEVEL" class="common_search_select w100">
                        <option value="">请选择</option>
                        <%=CustomerLevel%>
                    </select>
                    </span>
                    <span class="mr30 mb20">年龄：
                    <input id="AGE_FROM" type="text" class="common_search_input w50" />
                        至<input id="AGE_TO" type="text" class="common_search_input w50" />
                    </span>

                    <span class="mr30 mb20">可用积分：
                    <input id="CONSUME_POINT_FROM" type="text" class="common_search_input w50" />至
                        <input id="CONSUME_POINT_TO" type="text" class="common_search_input w50" />
                    </span>
                    <br />
                    <span class="mr30 mb20">所属店铺：<input type="text" id="ownShop" class="common_search_input w100" />
                        <input type="hidden" id="SHOP_CODE" value="" />
                    </span>
                    <span class="mr30 mb20">顾客纪念日：
                        <select id="MEMODAYTYPE" class="common_search_select w100">
                            <option value="">请选择</option>
                            <%=CustomerMemoDay%>
                        </select>
                        <input id="MEMODAY_FROM" type="text" onfocus="WdatePicker()" class="common_search_input w100" />至
                        <input id="MEMODAY_To" type="text" onfocus="WdatePicker()" class="common_search_input w100" />
                    </span>
                    <br />
                    <span class="mr30 mb20">所在省：
                    <select id="province" class="common_search_select w100">
                        <option value="">请选择</option>
                        <%=Province%>
                    </select>市
                        <select id="city" disabled="disabled" class="common_search_select w100">
                            <option value="">请选择</option>
                        </select>
                        区
                        <select id="AREA_CODE" disabled="disabled" class="common_search_select w100">
                            <option value="">请选择</option>
                        </select>
                    </span>
                    <label>
                        <input type="checkbox" id="RemoveNoMobile" />不包含未留手机号人员</label>
                    <span style="display: block; margin-top: 8px;">
                        <input type="button" value="" id="btnSearch" class="common_btn_search mr30" />
                        <input type="button" value="" id="btnConfirm" class="common_btn_confirm mr30" />
                    </span>
                </div>
            </div>
            <div class="mb8"></div>
            <p class="mb8 f14"><strong>第二步：显示符合条件人员</strong></p>
            <div style="width: 690px;">
                <div style="width: 287px; float: left;" class="border_blue">
                    <h4 class="title">待选人员 <span class="fred" id="sourceNum">0名</span> &nbsp;&nbsp;</h4>
                    <div class="user_list">
                        <table class="common_table" border="0" cellspacing="0" cellpadding="0" width="100%">
                            <thead>
                                <tr>
                                    <th width="31%" align="left">顾客卡号</th>
                                    <th width="17%" align="left">姓名</th>
                                    <th width="52%" align="left">手机号</th>
                                </tr>
                            </thead>
                        </table>
                        <select multiple="multiple" id="CUSTOMER_SOURCE" style="width: 100%; height: 200px;">
                        </select>
                    </div>
                </div>
                <div class="pop_btn move2button">
                    <input type="button" value="添加>" id="btnMove" class="common_btn_w69" />
                    <input type="button" value="删除" id="btnBack" class="common_btn_w69" />
                    <input type="button" value="全部添加" id="btnMoveAll" class="common_btn_w69" />
                    <input type="button" value="全部删除" id="btnBackAll" class="common_btn_w69" />
                </div>
                <div style="width: 287px; float: left;" class="border_blue">
                    <h4 class="title">已选人员 <span class="fred" id="targetNum">0名</span> &nbsp;&nbsp;</h4>
                    <div class="user_list">
                        <table class="common_table" border="0" cellspacing="0" cellpadding="0" width="100%">
                            <thead>
                                <tr>
                                    <th width="31%" align="left">顾客卡号</th>
                                    <th width="17%" align="left">姓名</th>
                                    <th width="52%" align="left">手机号</th>
                                </tr>
                            </thead>
                        </table>
                        <select multiple="multiple" id="CUSTOMER_TARGET" style="width: 100%; height: 200px;">
                        </select>
                    </div>
                </div>
            </div>
            <br clear="all">
        </div>
    </form>
</body>
</html>
